// pages/my/components/model-card/index.js
const {
  myApi
} = require('../../../../api/index')
const app = getApp()
Component({

  /**
   * 组件的属性列表
   */
  properties: {
    modelData: {
      type: Object,
    }
  },
  attached() {
    let time = ''
    if (this.properties.modelData.lastModificationTime) {
      const date = new Date(this.properties.modelData.lastModificationTime);
      time = date.toLocaleString("zh-CN", {
        timeZone: "Asia/Shanghai"
      });
    };
    this.setData({
      time,
      tags: this.properties.modelData.bottomMoldType === "1" ? "室内" : this.properties.modelData.bottomMoldType === "2" ? "景观" : "建筑"
    })
  },
  /**
   * 组件的初始数据
   */
  data: {
    IMGBASEURL: app.globalData.IMGBASEURL,
    tags: ''
  },

  /**
   * 组件的方法列表
   */
  methods: {
   
    onDelet() {
      let _this = this
      wx.showModal({
        title: "",
        cancelText: "取消",
        confirmText: "确定",
        content: "确定要删除这个模型吗？",
        success(res) {
          if (res.confirm) {
            wx.showLoading({
              title: '请稍等',
            })
            myApi.deleteModel({
              "id": _this.properties.modelData.id
            }).then(e => {
              _this.triggerEvent('onDelet', {
                id: _this.properties.modelData.id
              });
              wx.hideLoading()
            })
          }
        },
      });
    }
  }
})